Ruby on Rails - redirection in ruby on rails- ruby on rails tutorial - rails guides - rails tutorial - ruby rails
We can perform redirection in Rails routes as follows
get '/stories', to: redirect('/posts')
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
match "/abc" => redirect("http://example.com/abc")
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
Wecan also redirect all unknown routes to a given path
match '*path' => redirect('/'), via: :get
# or
get '*path' => redirect('/')
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
match '*path' => redirect('/')